package com.mxdx.edu.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;

import com.mxdx.edu.constant.StaticConstants;

@Service
public class SessionUtil {

    public String setTokenSession(HttpServletRequest request){
        String token = StringUtils.getUUId();
        HttpSession session = request.getSession();
        session.setAttribute(StaticConstants.USER_SESSION_KEY, token);
        return token;
    }

    public String getTokenSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        String token = (String)session.getAttribute(StaticConstants.USER_SESSION_KEY);
        return token;
    }

    public void delete(HttpServletRequest request, String token){
        HttpSession session = request.getSession(false);
        session.removeAttribute(token);
    }

}
